<div class="pagecontainer pageoverflow">
    <div class="pageheader">
        View Quotation
    </div>
    <div style="clear: both;"></div>
        <div id="page_content">
            <div class="pageoverflow">
                <div class="pagetext">Quotation number<span class="error-star">*</span>:</div>
                <div class="pageinput">
                    <input type="text" readonly  size="60" value="QN<?php echo str_pad($this->quotations['qn_id'], 4, "0", STR_PAD_LEFT);?>" name="qn_id" id="qn_id">
                </div>
            </div>

            <div class="pageoverflow">
                <div class="pagetext">Quotation name<span class="error-star">*</span>:</div>
                <div class="pageinput">
                    <input type="text" readonly  size="60" value="<?php echo $this->quotations['qn_name']?>" name="qn_name" id="qn_name">
                </div>
            </div>

            <div class="pageoverflow">
                <p class="pagetext">Quotation date</p>
                <p class="pageinput">
                    <input type="text" readonly size="60" id="qn_created" value="<?php echo date('Y-m-d' , strtotime($this->quotations["qn_created"])); ?>" name="qn_created">
                </p>
            </div>

            <div class="pageoverflow">
                <div class="pagetext">Customer:</div>
                <div class="pageinput">
                    <input type="text" readonly size="60" value="<?php echo $this->quotations['cus_name']?>" name="cus_name" id="cus_name">
                </div>
            </div>

                
            <?php if ( count($this->quotationReference) > 0 ):?>
            <div class="pageoverflow">
                <div class="pagetext">Quotation Details: </div>
                <div class="pageinput">
                    <table style="width: 57%; margin: 0px;" class="pagetable">
                        <tbody>
                            <tr>
                                <th style="height: 30px;">Code</th>
                                <th style="height: 30px;">UOM</th>
                                <th style="height: 30px;">Description</th>
                                <th style="height: 30px;">Quantity</th>
                                <th class="<?php echo ($this->user->role =="ADMIN")?"":"display-none"; ?>" style="height: 30px;">Cost Price (RM)</th>
                                <th style="height: 30px;">Selling Price (RM)</th>
                            </tr>
                            <?php foreach($this->quotationReference as $_quotationReference): ?>
                            <tr class="row2">
                                <td><?php echo $_quotationReference['qnr_name'];?></td>
                                <td><?php echo $_quotationReference['qnr_uom'];?></td>
                                <td><?php echo ($_quotationReference['qnr_description'] == '')?"&nbsp;":nl2br($_quotationReference['qnr_description']) ;?></td>
                                <td><?php echo $_quotationReference['qnr_qty'];?></td>
                                <td class="<?php echo ($this->user->role =="ADMIN")?"":"display-none"; ?>"><?php echo $_quotationReference['qnr_materialcost'];?></td>
                                <td><?php echo $_quotationReference['qnr_materialsrp'];?></td>
                            </tr>
                            <?php endforeach;?>
                        </tbody></table>
                </div>
            </div>
            <?php endif;?>

            <?php if ( count($this->quotationImages) > 0 ):?>
            <?php foreach($this->quotationImages as $_quotationImages): ?>
            <div class="pageoverflow">
                <div class="calculator">
                    <div class="job-material-cnt">
                        <div class="cal-text-cnt">Quotation Image</div>
                        <?php
                            $thumb_src_path = $this->PUBLIC_PATH . "upload/quotation/thumb_".$_quotationImages['qni_image'];
                            $src_path = $this->PUBLIC_PATH . "upload/quotation/".$_quotationImages['qni_image'];
                        ?>
                        <img src="<?php echo $thumb_src_path; ?>" height="150" width="150"/>&nbsp;
                    </div>
                    <div class="job-material-cnt">
                        <div class="cal-text-cnt"> &nbsp;</div>
                        <a href="#" class="print-image" imagename="<?php echo $src_path;?>"><img width="28" height="28" src="<?php echo $this->IMAGE_PATH; ?>icons/system/print.png" alt="Print" title="Print" /></a>
                    </div>
                </div>
            </div>             
            <?php endforeach;?>
            <?php endif;?>
            
                <div class="pageoverflow <?php echo ($this->user->role == "ADMIN") ? "" : "display-none"; ?>">
                    <p class="pagetext">Total Cost Price (RM)</p>
                    <p class="pageinput">
                        <input type="text" readonly size="60" id="total_cost_price" value="<?php echo $this->quotations['qn_costprice']?>" name="qn_costprice">
                    </p>
                </div>

                <div class="pageoverflow">
                    <p class="pagetext">Total Selling Price (RM)</p>
                    <p class="pageinput">
                        <input type="text" readonly size="60" id="total_selling_price" value="<?php echo $this->quotations['qn_sellingprice']?>" name="qn_sellingprice">
                    </p>
                </div>
            
                <div class="pageoverflow">
                    <p class="pagetext">Profit/Loss margin (RM)</p>
                    <p class="pageinput">
                        <input type="text" readonly size="60" id="qn_profit_loss_margin" value="<?php echo $this->quotations['qn_profit_loss_margin']?>" name="qn_profit_loss_margin">
                    </p>
                </div>

                <div class="pageoverflow">
                    <p class="pagetext">&nbsp;</p>
                    <p class="pageinput">
                        <input type="button" title="Print" value="Print" onclick="printSelection()" name="submitbutton">
                        <input type="button" title="Back" value="Back" onclick="history.back();" name="submitbutton">
                    </p>
                </div>
                <div style="clear: both;"></div>
            </div>
    </div>
    <p class="pageback">
        <a class="pageback" href="<?php echo $this->url(array('controller' => 'quotation', 'action' => 'list'), null, TRUE) ?>">&#171; Back to Listing</a>
    </p>
<div class="clearb"></div>

<script type="text/javascript">
    
    $(document).ready( function(){
        $('.print-image').click(function (){
            imagename = $(this).attr('imagename');
            var content = "<img src='"+ imagename +"'>";
            var printscript = unescape("%3Cscript%3E function printscreen(){setTimeout('timeprint()',500)} function timeprint(){ window.print();}%3C/script%3E");
            content = content + printscript;
            var pwin = window.open('', 'print_content');
            pwin.document.open();
            pwin.document.write('<html><head></head><body onload="printscreen();">' + content + '</body></html>');
            // setTimeout(pwin.print(),3000);
            pwin.document.close();
        })
    })
    function printSelection() {
        var content = document.getElementById("printContent").innerHTML;
        var printscript = unescape("%3Cscript%3E function printscreen(){setTimeout('timeprint()',500)} function timeprint(){ window.print();}%3C/script%3E");
        content = content + printscript;
        var pwin = window.open('', 'print_content');
        pwin.document.open();
        
        pwin.document.write('<html><head><link type="text/css" rel="stylesheet" href="<?php echo $this->CSS_PATH."quotation.css";?>" media="screen"/><link type="text/css" rel="stylesheet" href="<?php echo $this->CSS_PATH."quotation.css";?>" media="print"/></head><body onload="printscreen();">' + content + '</body></html>');
        // setTimeout(pwin.print(),3000);

        pwin.document.close();

    }
</script>

